#include <QDesktopServices>
#include "HelpViewer.h"

HelpViewer::HelpViewer(QWidget *parent) : QTextBrowser(parent)
{
}

void HelpViewer::setHelpEngine(QHelpEngine *helpEngine)
{
    this->helpEngine = helpEngine;
}

QVariant HelpViewer::loadResource(int type, const QUrl &name)
{
    if (name.scheme() == "qthelp")
        return QVariant(helpEngine->fileData(name));
    else
        return QVariant("Invalid page");
}

void    HelpViewer::setSource(const QUrl& name)
{
    if (name.scheme() == "qthelp")
    {
        QTextBrowser::setSource(name);
    }
    else
    {
        QDesktopServices::openUrl(name);
    }
}
